package com.kun.demo03;


import org.junit.Test;

//测试线程状态
public class TestState {

    @Test
    public void test() throws InterruptedException {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread.State state = thread.getState();// NEW
        System.out.println(state);
        thread.start();
        state = thread.getState(); // RUNNABLE
        System.out.println(state);
        while(thread.getState() != Thread.State.TERMINATED){
            Thread.sleep(100);
            System.out.println(thread.getState());
        }
//        thread.start();//线程死亡后，不能再次启动
    }


}
